package de.koller.world.render;

import de.koller.oceanFramework.glyph.GlyphScreenGL;
import de.koller.oceanFramework.tree.Child;
import de.koller.reason.ReasonStart;
import de.koller.reason.gui.IRenderListener;
import de.koller.reason.gui.renderObj.GlyphRendering;
import de.koller.reason.gui.renderObj.IRenderObject;
import de.koller.reason.gui.renderObj.IRenderPosition;
import de.koller.reason.gui.renderObj.IVolatileRenderObject;
import de.koller.reason.resource.ResourceUtil;
import de.koller.world.WNode;
import org.lwjgl.opengl.GL11;

public class WorldRender extends WNode {

	public static final int S_WIDTH = 800, S_HEIGHT = 600;
	@Child private final GlyphScreenGL statusView = ResourceUtil.createGlyphScreen( 128, 128 );
	
	@Override
	protected void init() {
		super.init();
		GL11.glMatrixMode( GL11.GL_PROJECTION );
		GL11.glLoadIdentity();

		GL11.glOrtho( 0, S_WIDTH, S_HEIGHT, 0, -1000, 1000 );
		
		GL11.glMatrixMode( GL11.GL_MODELVIEW );
		GL11.glLoadIdentity();
		
		GL11.glEnable( GL11.GL_CULL_FACE );
		GL11.glCullFace( GL11.GL_BACK );

		GL11.glEnable( GL11.GL_DEPTH_TEST );
		GL11.glDepthFunc( GL11.GL_LEQUAL );
		
		GL11.glAlphaFunc( GL11.GL_GREATER, 0.1f );
		GL11.glEnable( GL11.GL_ALPHA_TEST );
	}
	
	public final void renderSzene() {
		GL11.glClear( GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT );
		GL11.glColor3f( 1, 1, 1 );
		
		statusView.getRenderer().setCurrentFontColor( 0xffffffff );
		statusView.getRenderer().setCurrentBackColor( 0xff000000 );
		statusView.getRenderer().renderString( 0, 0, wroot.getLatency() + "ms" );
		statusView.updateBuffer();
		statusView.getTexture().draw2D( 0, 0, 128, 128, 100 );
	}
	
}
